package com.dap.configuration.service.config.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baidu.disconf.core.common.constants.Constants;
import com.baidu.disconf.core.common.constants.DisConfigTypeEnum;
import com.baidu.disconf.core.common.json.ValueVo;
import com.baidu.disconf.web.service.config.bo.Config;
import com.baidu.disconf.web.service.config.service.impl.ConfigFetchMgrImpl;
import com.baidu.disconf.web.service.config.utils.ConfigUtils;
import com.dap.configuration.service.config.dao.ConfigExtensionDao;
import com.dap.configuration.service.config.service.ConfigFetchExtensionMgr;

/**
 * @author dengxiang
 * @version 2014-6-16
 */
@Service
public class ConfigFetchMgrExtensionImpl implements ConfigFetchExtensionMgr {


    private static final Logger LOG = LoggerFactory.getLogger(ConfigFetchMgrImpl.class);

    @Autowired
    private ConfigExtensionDao configExtensionDao;

	@Override
	public ValueVo getConfItemByParameter(Long appId, Long envId,
			String version, String key, String bankKey) {
		Config config = configExtensionDao.getByParameter(appId, envId, version, key, DisConfigTypeEnum.ITEM,bankKey,null);
        if (config == null) {
            return ConfigUtils.getErrorVo("cannot find this config");
        }
        ValueVo valueVo = new ValueVo();
        valueVo.setValue(config.getValue());
        valueVo.setStatus(Constants.OK);

        return valueVo;
	}

	@Override
	public Config getConfByParameter(Long appId, Long envId, String version,
			String key, String bankKey, DisConfigTypeEnum disConfigTypeEnum) {
		Config config = configExtensionDao.getByParameter(appId, envId, version, key, disConfigTypeEnum,bankKey,null);
        return config;
	}

}
